package com.talkology.pilot.student.controller;

import com.talkology.pilot.database.model.WxGroup;
import com.talkology.pilot.student.service.IWxGroupService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

@RestController
@RequestMapping(value = "/wxgroup")
public class WxGroupController {
    @Autowired
    private IWxGroupService service;

    @RequestMapping(value = "/all", method= RequestMethod.GET)
    @ResponseBody
    public List<WxGroup> getByFilter(@RequestParam(value = "useFlag", required = false) Integer useFlag,
                                          @RequestParam(value = "studentId", required = false) String studentId) {
        return service.getAllByFilter(useFlag, studentId);
    }

    @RequestMapping(value = "/info", method= RequestMethod.GET)
    @ResponseBody
    public WxGroup getInfo(@RequestParam(value = "index", required = true) Integer index) {
        return service.getInfo(index);
    }

    @RequestMapping(value = "/import", method= RequestMethod.POST)
    @ResponseBody
    public void batchImport(@RequestParam(required = true) MultipartFile profile) {
        service.batchImport(profile);
    }

    @RequestMapping(value = "/occupyNewOne", method= RequestMethod.POST)
    @ResponseBody
    public String occupyNewOne(@RequestParam(value = "studentId", required = false) String studentId) {
        return service.occupyNewOne(studentId);
    }

    @RequestMapping(value = "/update", method= RequestMethod.PUT)
    @ResponseBody
    public void updateInfo(@RequestBody WxGroup record) {
        service.edit(record);
    }

    @RequestMapping(value = "/delete", method= RequestMethod.DELETE)
    @ResponseBody
    public void deleteInfo(@RequestParam(value = "index", required = false) Integer index) {
        service.delete(index);
    }
}
